﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SAPInvoker.Controls
{
    public partial class TableRFCParameterInput : UserControl
    {
        private DataTable _data;
        private int _posotion;
        private bool _isCollapse = false;
        private int initialHeight;
        public delegate void CollapseHandler(object sende,EventArgs e);

        public event CollapseHandler CollapseChecked;

        private void OnCollapseChecked()
        {
            if (CollapseChecked != null)
            {
                CollapseChecked(this, new EventArgs());
            }
        }
        public TableRFCParameterInput()
        {
            InitializeComponent();
            this.initialHeight = this.Height;
            this.gridTable.AutoGenerateColumns = true;
            this.gridTable.AllowUserToAddRows = true;
            this.gridTable.AllowUserToDeleteRows = true;
            this.gridTable.EditMode = DataGridViewEditMode.EditOnEnter;
        }

        private void chkCollapse_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkBox = sender as CheckBox;
            if (chkBox.Checked)
            {
                this.gridTable.Hide();
                this._isCollapse = true;
                OnCollapseChecked();
            }
            else
            {
                this.gridTable.Show();
                this._isCollapse = false;
                OnCollapseChecked();
            }
           

            
        }

        public DataTable Data
        {
            get
            {
               return (DataTable)this.gridTable.DataSource;
            }
            set
            {
                this._data = value;
                object objPos = value.ExtendedProperties["Position"];
                if (objPos != null)
                {
                    this._posotion = (int)objPos;
                    this.lblPosition.Text = objPos.ToString();
                }

                this.lblName.Text = value.TableName;
                this.gridTable.DataSource = value;

            }
        }

        public int Position
        {
            get { return this._posotion; }
            set { this._posotion = value; this.lblPosition.Text = value.ToString(); }
        }

        public bool IsCollapse
        {
            get { return this._isCollapse; }
        }
        
    }
}
